package bmatch.tech.hello.dao;

import bmatch.tech.hello.dao.buider.CitySqlBuilder;
import bmatch.tech.hello.dao.buider.UserSqlBuider;
import bmatch.tech.hello.model.User;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

@Component
@Mapper
public interface UserMapper {

    @SelectProvider(type = UserSqlBuider.class, method = "buildQueryUser")
    List<User> loginQuery(String name, String pwd);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated Thu Dec 13 14:16:43 CST 2018
     */
    @Delete({
            "delete from user",
            "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(User userId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated Thu Dec 13 14:16:43 CST 2018
     */
    @Insert({
            "insert into user (user_id, name, ",
            "pwd)",
            "values (#{userId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
            "#{pwd,jdbcType=VARCHAR})"
    })
    int insert(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated Thu Dec 13 14:16:43 CST 2018
     */
    @Select({
            "select",
            "user_id, name, pwd",
            "from user",
            "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pwd", property = "pwd", jdbcType = JdbcType.VARCHAR)
    })
    User selectByPrimaryKey(User userId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated Thu Dec 13 14:16:43 CST 2018
     */
    @Select({
            "select",
            "user_id, name, pwd",
            "from user"
    })
    @Results({
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pwd", property = "pwd", jdbcType = JdbcType.VARCHAR)
    })
    List<User> selectAll();

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table user
     *
     * @mbg.generated Thu Dec 13 14:16:43 CST 2018
     */
    @Update({
            "update user",
            "set name = #{name,jdbcType=VARCHAR},",
            "pwd = #{pwd,jdbcType=VARCHAR}",
            "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(User record);
}